using System.IO;
using System.Xml;

namespace MMXSaveGameConverter
{
    internal sealed class XmlFileWriter : FileWriterBase
    {
        private readonly string _xmlPath;
        private readonly string _pngPath;

        public XmlFileWriter(SaveGameViewItem item)
            : base(item)
        {
            _xmlPath = Path.ChangeExtension(item.FullPath, ".xml");
            _pngPath = Path.ChangeExtension(item.FullPath, ".png");
        }

        public override void Write()
        {
            XmlDocument doc = Save2Xml.SerializeSaveGame(SaveGame);
            SaveFileMeta meta = new SaveFileMeta(Item.Name);
            meta.ToXml(doc);
            doc.Save(_xmlPath);

            using (Stream output = File.Create(_pngPath))
                WriteScreenshot(output);
        }
    }
}